---@class Battle.EntityEventSystem:Battle.EntityComponent
local EntityEventSystem = Battle.CreateClass("EntityEventSystem",Battle.EntityComponent)
Battle.EntityEventSystem = EntityEventSystem
function EntityEventSystem:OnCreate()
    self.evenList = {}
end
function EntityEventSystem:OnDestroy()
    self.evenList = nil
end
function EntityEventSystem:Register(eventId, func, tbl)
    if self.evenList == nil then return end
    local evList = self.evenList[eventId]
    if  evList == nil then
        evList = {}
        self.evenList[eventId] = evList;
    end
    for k,v in pairs(evList) do
        if v.f == func and v.tb == tbl then
            return
        end
    end
    table.insert(evList,{f = func,tb = tbl});
end
function EntityEventSystem:UnRegister(eventId, func, tbl)
    if self.evenList == nil then return end
    local eventList = self.evenList[eventId];
    if eventList == nil then return end
    for k,v in pairs(eventList) do
        if v.f == func then
            if v.tb == nil or v.tb == tbl then
                table.remove(eventList,k)
                break
            end
        end
    end
end
---@param args BattleEvent
function EntityEventSystem:FireEvent(eventId, args)
    local eventFunList = self.evenList[eventId];
    if eventFunList ~= nil then
        for k,v in pairs(eventFunList) do
            if v and v.f ~= nil then
                if v.tb then
                    v.f(v.tb,args)
                else
                    v.f(args)
                end
            end
        end
    end
    Battle.GlobalEventSystem.BroadCast(eventId,args)
end